package logic

import (
	"context"
	"gorm.io/gorm"
	"host/inits"
	"host/model"

	"host/hostrpc/hostrpc"
	"host/hostrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdatePasswordLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdatePasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdatePasswordLogic {
	return &UpdatePasswordLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UpdatePasswordLogic) UpdatePassword(in *hostrpc.UpdatePasswordRequest) (*hostrpc.UpdatePasswordResponse, error) {
	// todo: add your logic here and delete this line

	var user model.User

	inits.DB.Debug().Where("id=?", in.Id).Find(&user)

	m := model.User{
		Model:    gorm.Model{ID: user.ID},
		Mobile:   in.Mobile,
		Password: in.Password,
	}
	inits.DB.Updates(&m)
	return &hostrpc.UpdatePasswordResponse{
		UpdateId: int64(m.ID),
	}, nil
}
